package com.example.carbon.server.info;

import com.alibaba.fastjson2.JSON;
import com.example.carbon.Dto.mesSave.Search;
import com.example.carbon.dao.MesSaveDao;
import com.example.carbon.pojo.mesSave.MesSave;
import com.example.carbon.server.MesSaveServer;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MesSaveInfo implements MesSaveServer {
    @Resource
    MesSaveDao mesSaveDao;


    @Override
    public String getAllMesInfo() {
        try {
            return JSON.toJSONString(mesSaveDao.getAllMesSaveInfo());
        } catch (Exception e) {
            log.info(e.getMessage());
            return null;
        }
    }

    @Override
    public boolean updateMesInfo(MesSave mesSave) {
        if (mesSave == null)
            return false;
        try {
            return mesSaveDao.updateMesInfo(mesSave);
        } catch (Exception e) {
            log.info(e.getMessage());
            return false;
        }
    }

    @Override
    public boolean insertNewMesInfo(MesSave mesSave) {
        if (mesSave == null)
            return false;
        try {
            return mesSaveDao.insertNewMesInfo(mesSave);
        } catch (Exception e) {
            log.info(e.getMessage());
            return false;
        }
    }

    @Override
    public String searchMesBykey(Search search) {
        log.info(search.toString());
        if (search == null)
            return null;
        try {
            return JSON.toJSONString(mesSaveDao.searchByKey(search));
        } catch (Exception e) {
            log.info(e.getMessage());
            return null;
        }
    }

    @Override
    public boolean deleteById(int id) {
        if (id == 0)
            return false;
        try {
            return mesSaveDao.deleteById(id);
        } catch (Exception e) {
            log.info(e.getMessage());
            return false;
        }
    }
}
